package validator

import (
	"fmt"
	"github.com/go-playground/locales/zh"
	ut "github.com/go-playground/universal-translator"
	"github.com/go-playground/validator/v10"
	zhTrans "github.com/go-playground/validator/v10/translations/zh"
)

var Validator *validator.Validate
var trans ut.Translator

func init() {
	Validator = validator.New()

	//中文翻译器
	uniTrans := ut.New(zh.New())
	trans, _ = uniTrans.GetTranslator("zh")
	//注册翻译器到验证器
	err := zhTrans.RegisterDefaultTranslations(Validator, trans)
	if err != nil {
		panic(fmt.Sprint("registerDefaultTranslations fail:%s\n", err.Error()))
	}

}
